import { Dispatch } from 'redux';
import type { IStateType, ILiveBroadData } from './index.d';

export const MODULE_NAME: string = 'LiveBroadRoom';

export const types = {
  LIVE_BROAD_DATA: `${MODULE_NAME}/LIVE_BROAD_DATA`, // 视频数据
}

export default (state: IStateType = {
  liveBroadData: null
}, action: any) => {
  switch (action.type) {
    case types.LIVE_BROAD_DATA:
      return Object.assign({}, state, {
        liveBroadData: action.data
      })
    default: return state
  }
}

/**
 * 获取列表数据
*/
export const getDataById = (id: string) => {
  return async (dispatch: Dispatch): Promise<void> => {
    try {
      const data: ILiveBroadData[] = [{
        id: '10001',
        url: [
          {
            src: 'http://flv2828176d.live.126.net/live/fc30740a6326488487b6fde20793d1e2.flv?netease=flv2828176d.live.126.net',
            type: 'video/x-flv'
          },
          {
            src: 'http://pullhls2828176d.live.126.net/live/fc30740a6326488487b6fde20793d1e2/playlist.m3u8',
            type: 'application/x-mpegURL'
          },
          {
            src: 'rtmp://v2828176d.live.126.net/live/fc30740a6326488487b6fde20793d1e2',
            type: 'rtmp/flv'
          }
        ]
      }, {
        id: '10002',
        url: [
          {
            src: 'http://flv2828176d.live.126.net/live/643b307d7d264d99b72ae1ec8fec3bb9.flv?netease=flv2828176d.live.126.net',
            type: 'video/x-flv'
          },
          {
             src: 'http://pullhls2828176d.live.126.net/live/643b307d7d264d99b72ae1ec8fec3bb9/playlist.m3u8',
            type: 'application/x-mpegURL'
          },
          {
            src: 'rtmp://v2828176d.live.126.net/live/643b307d7d264d99b72ae1ec8fec3bb9',
            type: 'rtmp/flv'
          }
        ]
      }, {
        id: '10005',
        url: [
          {
            src: 'http://flv2828176d.live.126.net/live/293f4ae56d044d038e19ae0106d37e0c.flv?netease=flv2828176d.live.126.net',
            type: 'video/x-flv'
          },
          {
             src: 'http://pullhls2828176d.live.126.net/live/293f4ae56d044d038e19ae0106d37e0c/playlist.m3u8',
            type: 'application/x-mpegURL'
          },
          {
            src: 'rtmp://v2828176d.live.126.net/live/293f4ae56d044d038e19ae0106d37e0c',
            type: 'rtmp/flv'
          }
        ]
      }, {
        id: '10006',
        url: [
          {
            src: 'http://flv2828176d.live.126.net/live/a7e88cfa0e624d4ba80b95ce9ce0913d.flv?netease=flv2828176d.live.126.net',
            type: 'video/x-flv'
          },
          {
             src: 'http://pullhls2828176d.live.126.net/live/a7e88cfa0e624d4ba80b95ce9ce0913d/playlist.m3u8',
            type: 'application/x-mpegURL'
          },
          {
            src: 'rtmp://v2828176d.live.126.net/live/fc30740a6326488487b6fde20793d1e2',
            type: 'rtmp/flv'
          }
        ]
      }]

      dispatch({
        type: types.LIVE_BROAD_DATA,
        data: data.find(item => item.id === id)
      })
    } catch { }
  }
}
